//
//  StatisticsViewController.m
//  rrqs
//
//  Created by 朱耀春 on 2019/5/3.
//

#import "StatisticsViewController.h"
#import "StatisticsChildViewController.h"
#import "SGPagingView.h"
#import "CGXPickerView.h"


@interface StatisticsViewController ()
<SGPageTitleViewDelegate,
SGPageContentScrollViewDelegate>

@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentScrollView *pageContentCollectionView;

@end

@implementation StatisticsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setRightButton];
    [self setupPageView:@[@"昨天",@"今天",@"本月",@"上月"]];
}
//日历
-(void)setRightButton{
    ///设置返回按钮
    UIImage * rightImg = kCalendarImage;
    UIBarButtonItem * rightBI = [[UIBarButtonItem alloc] initWithImage:rightImg style:UIBarButtonItemStylePlain target:self action:@selector(RightButAction)];
    self.navigationItem.rightBarButtonItem = rightBI;
    
}
-(void)RightButAction{
    [CGXPickerView showDatePickerWithTitle:@"请选择日期" DateType:UIDatePickerModeDate DefaultSelValue:nil MinDateStr:nil MaxDateStr:nil IsAutoSelect:NO Manager:nil ResultBlock:^(NSString *selectValue) {
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"UpdateData" object:selectValue];
        
    }];
}

- (void)setupPageView:(NSArray *)titleArr {
    
    SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
    configure.titleSelectedColor = kgreen_color;
    configure.indicatorColor     = kgreen_color;
    configure.titleColor         = kBlackColor;
    _pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44) delegate:self titleNames:titleArr configure:configure];
    self.pageTitleView.backgroundColor = kWhiteColor;
    [self.view addSubview:_pageTitleView];
    //添加子控制器
    NSMutableArray * childArr = [NSMutableArray array];
    for (int i = 0 ; i < titleArr.count ; i ++) {
        StatisticsChildViewController *childVC = NewFunctionStoryboard(@"StatisticsChildViewController");
        childVC.status = [NSString stringWithFormat:@"%d",i + 1];
        [childArr addObject:childVC];
    }
   
    
    CGFloat ContentCollectionViewHeight = kMainScreenHeight - CGRectGetMaxY(_pageTitleView.frame) - 64;
    self.pageContentCollectionView = [[SGPageContentScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_pageTitleView.frame), self.view.frame.size.width, ContentCollectionViewHeight) parentVC:self childVCs:childArr];
    _pageContentCollectionView.delegatePageContentScrollView = self;
    [self.view addSubview:_pageContentCollectionView];
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentCollectionView setPageContentScrollViewCurrentIndex:selectedIndex];
}

- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex{
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
    
}



@end
